<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<title>UDPChat  Sample</title>
<link rel="stylesheet" type="text/css" href="../../../../docs/rotor.css">
</head>

<body>		


<h1>UDPChat  Sample</h1>


<h2>Sample Overview</h2>


<p>This sample illustrates using the <b>UdpClient</b> class to create a chat client.
</p>
<p>This sample is a functional chat client. It uses the user datagram protocol (UDP) to send and receive chat 
messages with other users that are also using the client. The program 
illustrates use of the UdpClient class and threading.</p>


<p>THe <b>UdpClient</b> object is initialized with a constructor call that sets 
the port that the object will listen on. The object then joins a Multicast 
group. This code can be found in the <b>Initialize</b> function of the sample 
code.</p>
<p>Once initialized, the <b>UdpClient</b> listens for incoming messages with the <b>
Receive</b> function, which can be found in the <b>Listener</b> function of the 
sample code. The <b>Receive</b> function returns an array of bytes, containing 
the data sent. This data can be converted into a string with the ASCII object <b>
GetString</b> function.</p>
<p>Sending data is also easy. The <b>UdpClient</b> class includes a function 
called <b>Send,</b> which sends out a byte array to every class that is listening 
on the Multicast group.</p>


<h2>Sample Source and Build Output Locations</h2>


<p>The sample source is found in sscli20\samples\howto\net\udpchat.&nbsp; </p>


<p>The source file is:</p>


<ul class="none">
  <li><a href="udpchat.cs">udpchat.cs</a></li>
</ul>


<p>The build output location is %_NTTREE%\samples\howto\net\udpchat.&nbsp; 
The output file is an executable assembly named udpchat.exe.</p>


<h2>Building the Sample</h2>


<p>All samples are built from the buildall script.&nbsp;  </p>


<p>You can also build all the 
samples by switching to the root of the sample directory, sscli20\samples, and typing 
<code>build -c</code>.</p>


<p>You can build this specific sample  by switching to the sample directory and typing 
<code>build -c</code>.</p>


<h2>Running the Sample</h2>


<p>These steps require that the Shared Source CLI (SSCLI) be already built and 
functional.</p>


<ol>
  <li>Run  env.bat. </li>
  <li>Switch to the %_NTTREE%\samples\howto\net\udpchat directory.</li>
  <li>Type the following command:<blockquote>


<p>clix udpchat.exe</p>


  </blockquote>


  </li>
  <li>You will need to run another instance of the udpchat application on 
  another system in order to test the functionality.</li>
</ol>


<hr>


<p><i>Copyright (c) 2006 Microsoft Corporation. All rights reserved.</i></p>
</body> 
</html>